home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: [Help] I can`t find m
- Date: 25 Feb 1996 09:08:27 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4gp8ub$mcs@gail.ripco.com>
- NNTP-Posting-Host: golden.ripco.com
-
- etoivane@direct.ca (Ed Toivanen) in reply to the message
- <4ggvgr$1b2@aurora.engr.LaTech.edu> wrote in
- <4givk5$bqk@aphex.direct.ca> the code which I have revised below.
-
- As usual, my changes and comments are marked with `/* mha - ... */',
- and, as usual, not all changes reflect actual errors in the code.
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define NAMESIZE 100
- #define BUFSIZE 4
-
- int main(void)
- {
- char buf[BUFSIZE];
- char name[NAMESIZE];
- int age, next_age = 1; /* mha - was `int age, next_age;',
- * which leaves next_age unintialized
- * before the 'next_age += age;'
- * statement */
-
- printf("Please enter your name:\t");
- fflush(stdout); /* mha - added. Make sure the above
- * appears in stdout before the
- * fgets() below. */
- fgets(name, sizeof name, stdin); /* mha - was `name = fgets(buf,
- * sizeof(buf), stdin);', but
- * `name' is an array[NAMESIZE]
- * of char, not a pointer to
- * char. You might consider
- * some error checking here. */
- printf("\nPlease enter your age:\t");
- fflush(stdout); /* mha - added */
- fgets(buf, sizeof buf, stdin); /* mha - moved fgets() out of
- * atoi() call. Now it's your job
- * to add some error checking. */
- age = atoi(buf); /* mha - some error checking on the
- * legality of the contents of buf
- * would be nice. (Your job) */
- next_age += age; /* mha - (unchanged)
- * Of course, you could just
- * increment age (`age++;'), and
- * replace `next_age' with `age' in the
- * printf() following. Or you could, if
- * you need to have both these
- * variables, have `next_age = age+1;' */
- printf("\nHi, %s ,next year, you will be %d\n", name, next_age);
- return 0; /* mha - note: parens around `0'
- * unneeded */
- }
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-